package com.jxwifi.cloud.quickclean.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.bean.AssemRecordsBean;

import java.util.List;

public class CycleAdapter extends RecyclerView.Adapter<CycleAdapter.ViewHolder> {

    private Context context;
    private List<AssemRecordsBean> list;

    public CycleAdapter(Context context, List<AssemRecordsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.assemble_type_item, parent, false));
        // 实例化展示的view
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.assemble_type_item, parent, false);
        // 实例化viewholder
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (!list.isEmpty()) {
            // 因为getItemCount返回int最大值，而我们设置的数据不可能那么多，所以在为item绑定数据的时候，我们
            // 这里采用取余的方法，这样就能保证每一项item都是有值的，但为了不重复就要求我们的样本数据多一点
           // holder.mTvMapSearchAddress.setText(list.get(position % list.size()));
            AssemRecordsBean mBeanList= list.get(position %list.size());
            holder.mTvMapSearchAddress.setText(mBeanList.getNickname());
        }
    }

    @Override
    public int getItemCount() {
        // 返回int最大值
        return list == null ? 0 : Integer.MAX_VALUE;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View mContainer;
        TextView mTvMapSearchAddress;//地址
        //TextView mTvMapSearchAddressDetailed;//详细地址


        public ViewHolder(View itemView) {
            super(itemView);
            mContainer = itemView;
            mTvMapSearchAddress = (TextView) mContainer.findViewById(R.id.assemble_main_package);
            // mTvMapSearchAddressDetailed = (TextView) itemView.findViewById(R.id.tv_map_search_address_detailed);
        }
    }
}


